package com.blog.mapper;

import com.blog.VO.ArticleWithCategory;
import com.blog.dto.ArticleCardDTO;
import com.blog.dto.ArticleDTO;
import com.blog.entity.Article;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;


/**
* @author 电脑小白
* @description 针对表【blog】的数据库操作Mapper
* @createDate 2025-07-03 18:45:41
* @Entity generator.domain.Blog
*/


public interface ArticleMapper {

    @Insert("insert into blog(id,title,content,create_time,view_count,category_id,status,author,author_id) values(#{Id},#{title},#{content},#{createTime},#{viewCount},#{categoryId},#{status},#{author},#{authorId})")
    void insertarticle(Article article);

    @Select("select id,title,content,create_time as createTime,update_time as updateTime,view_count as viewCount," +
            "category_id as categoryId,status,author,author_id as authorId from blog where id=#{articleId}")
    Article getarticlebyid(Integer articleId);

    @Select("select id,title,content,create_time as createTime,update_time as updateTime,view_count as viewCount," +
            "category_id as categoryId,status,author,author_id as authorId from blog order by createTime desc")
    List<Article> getarticlecards();

    @Select("select count(*) from blog")
    Integer get_article_counts();

    @Select("select sum(view_count) from blog")
    Integer get_article_view_counts();

    @Select("select id,title,content,create_time as createTime,update_time as updateTime,view_count as viewCount," +
            "category_id as categoryId,status,author,author_id as authorId from blog where category_id = #{categoryId}")
    List<Article> get_category_page_list(Integer categoryId);

    @Select("select id,title,content,create_time as createTime,update_time as updateTime,view_count as viewCount," +
            "category_id as categoryId,status,author,author_id as authorId from blog where id in (select blog_id from blog_tag where tag_id = #{tagId})")
    List<Article> get_tag_page_list(Integer tagId);

    @Select("select id,title,content,create_time as createTime,update_time as updateTime,view_count as viewCount," +
            "category_id as categoryId,status,author,author_id as authorId from blog")
    List<Article> getAllArticles();
}




